package com.atguigu.test.dacahngmainshitidierji.queue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;

/**
 * 2 * @Author: madonghui
 * 3 * @Date: 2020/11/11 18:06
 * 4
 */
public class SyncronousBlockingQueue {
    public static void main(String[] args) {
        //特点就是put一个没有take掉就会一直阻塞知道take掉才能正常运行
        BlockingQueue<String> blockingQueue = new SynchronousQueue<>();

        new Thread(()->{
            try {
                blockingQueue.put("a");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }            try {
                blockingQueue.put("a");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }            try {
                blockingQueue.put("a");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        },"AA").start();

        new Thread(()->{
            try {
                blockingQueue.take();
                blockingQueue.take();
                blockingQueue.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        },"BB").start();
    }
}
